package de.gwtprime.server.servlets;

import org.apache.log4j.Logger;

import com.google.web.bindery.requestfactory.server.ExceptionHandler;
import com.google.web.bindery.requestfactory.server.RequestFactoryServlet;
import com.google.web.bindery.requestfactory.shared.ServerFailure;

/**
 * Provide custom Exception handler and service decorator to the request factory servlet
 */
public class PrimeRequestFactoryServlet extends RequestFactoryServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public PrimeRequestFactoryServlet() {
		super(new PrimeExceptionHandler(), new PrimeServiceLayerDecorator());
	}

	static class PrimeExceptionHandler implements ExceptionHandler {
		private static final Logger logger = Logger.getLogger( PrimeExceptionHandler.class );

		@Override
		public ServerFailure createServerFailure( Throwable throwable ) {
			logger.error( "Server error occured: ", throwable );
			return new ServerFailure( throwable.getMessage(), throwable.getClass().getName(), throwable.getStackTrace().toString(), true );
		}
	}

}
